home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / VALIDDIR.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  2KB  |  52 lines

  1. @echo OFF
  2. REM **************************************************************************
  3. REM *** ValidDir.bat   Check if the specified directory is valid.  Return  ***
  4. REM *** ver.1          errorlevel 0 if it's OK, else ERRORLEVEL 1.  If two ***
  5. REM ***                parameters are given then print error if problem.   ***
  6. REM **************************************************************************
  7. CEnvi %0.bat %1 %2
  8. GOTO CENVI_EXIT
  9.  
  10. main(argc,argv)
  11. {
  12.    RetCode = 1; // assume failure
  13.    if ( 1 == argc  ||  !strcmpi(argv[1],"/?")  ||  !stricmp(argv[1],"/help") ) {
  14.       Instructions();
  15.    } else {
  16.       RetCode = ( ValidSubDirectoryName(argv[1],argc==3) ) ? 0 : 1 ;
  17.    }
  18.    return( RetCode );
  19. }
  20.  
  21. ValidSubDirectoryName(DirName,PrintMessageIfInvalid)
  22.    // test if DirName is a valid directory name.  If it is then return TRUE, else
  23.    // print message if PrintMessageIfInvalid is True and return FALSE.  ?This does
  24.    // not work, by the way, on the root directory
  25. {
  26.    // append "\." to name to check for directory
  27.    sprintf(TestDir,"%s\\.",FullPath(DirName));
  28.    if ( 0 == DirName[0]
  29.      || '\\' == DirName[strlen(DirName)-1]
  30.      || NULL == Directory(TestDir,FALSE,0xFFFF,FATTR_SUBDIR) ) {
  31.       if ( PrintMessageIfInvalid )
  32.          fprintf(stderr,"\"%s\" is not a valid sub-directory name.\a\n",DirName);
  33.       return FALSE;
  34.    }
  35.    return TRUE;
  36. }
  37.  
  38. Instructions()
  39. {
  40.    printf("\n")
  41.    printf("   ValidDir.bat - Test if a subdirectory name is valid\n")
  42.    printf("\n")
  43.    printf("   USAGE: ValidDir SubdirSpec [PrintError]\n")
  44.    printf("\n")
  45.    printf("          Check if subdirectory name is valid, and return ERRORLEVEL 0 if it is\n")
  46.    printf("          and ERRORLEVEL 1 if it is not.  If PrintError is supplied then a\n")
  47.    printf("          message will be printed if directory is invalid.\n")
  48.    printf("\n")
  49. }
  50.  
  51. :CENVI_EXIT
  52.